package com.tiancheng.trade.authserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tiancheng.trade.authserver.dto.*;
import com.tiancheng.trade.authserver.entity.AuthApplication;
import com.tiancheng.trade.authserver.entity.AuthOrg;
import com.tiancheng.trade.authserver.mapper.AuthOrgMapper;
import com.tiancheng.trade.authserver.model.query.OrgQuery;
import com.tiancheng.trade.authserver.model.reponse.UserOrgInfoResult;
import com.tiancheng.trade.commom.core.data.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @Author: kellen
 * @Description:
 * @Date: create in 2024/11/12 11:00
 */
@Service
public class AuthOrgServiceImpl extends ServiceImpl<AuthOrgMapper, AuthOrg> implements IAuthOrgService {
    @Override
    public List<OrgOptionDTO> getOptions(OrgQuery param) {
        List<AuthOrg> orgs=this.list(new LambdaQueryWrapper<AuthOrg>().eq(Objects.nonNull(param.getId()),AuthOrg::getId,param.getId())
                .eq(StringUtils.isNotEmpty(param.getApplicationId()),AuthOrg::getApplicationId,param.getApplicationId())
                .eq(Objects.nonNull(param.getOrder()),AuthOrg::getOrder,param.getOrder())
                .eq(StringUtils.isNotEmpty(param.getName()),AuthOrg::getName,param.getName())
                .eq(StringUtils.isNotEmpty(param.getCode()),AuthOrg::getCode,param.getCode())
                .eq(Objects.nonNull(param.getParentId()),AuthOrg::getParentId,param.getParentId())
                .eq(Objects.nonNull(param.getType()),AuthOrg::getType,param.getType()));

        List<OrgOptionDTO> result = new LinkedList<>();
        Set<Long> ids = new HashSet<>();
        for (AuthOrg org : orgs) {
            ids.add(org.getId());
        }

        final List<AuthOrg> songOrgs = this.list(new LambdaQueryWrapper<AuthOrg>().in(AuthOrg::getParentId, ids));
        Set<String> exSonIds = new HashSet<>();
        songOrgs.forEach(songOrg -> exSonIds.add(songOrg.getParentId()));
        for (AuthOrg org : orgs) {
            OrgOptionDTO dto = new OrgOptionDTO();
            BeanUtils.copyProperties(org, dto, "parent");
            result.add(dto);
            dto.setIsLeaf(!exSonIds.contains(org.getId()));
        }
        return result;
    }

    @Override
    public PageInfo<OrgListDTO> getTengyunPageInfo(OrgQuery param) {
        return null;
    }

    @Override
    public AuthOrg getByApplicationIdAndCode(String applicationId, String code) {
        return null;
    }

    @Override
    public OrgDetailDTO getDetail(String id) {
        return null;
    }

    @Override
    public String saveByDTO(OrgAddUpdateDTO param) {
        return null;
    }

    @Override
    public List<UserOrgInfoResult> api_getUserOrgInfo(String userId) {
        return null;
    }

    @Override
    public Map<String, Object> ossSave(Map<String, String> param) {
        return null;
    }

    @Override
    public List<Map<String, Object>> ossGetList(Map<String, String> param) {
        return null;
    }

    @Override
    public Map<String, Object> ossUpdate(Map<String, String> param) {
        return null;
    }

    @Override
    public Map<String, Object> ossGetDetail(Map<String, Object> param) {
        return null;
    }

    @Override
    public void ossDelete(String id) {

    }

    @Override
    public void ossBatchAddSon(Map<String, String> param) {

    }

    @Override
    public PageInfo<Map<String, Object>> ossGetOrgRolePageInfo(Map<String, String> param) {
        return null;
    }

    @Override
    public PageInfo<Map<String, Object>> ossGetUserRolePageInfo(Map<String, String> param) {
        return null;
    }

    @Override
    public Map<String, Object> ossAddRole(Map<String, String> param) {
        return null;
    }

    @Override
    public void ossDeleteRole(Map<String, Object> param) {

    }

    @Override
    public Map<String, Object> ossAddUser(Map<String, String> param) {
        return null;
    }

    @Override
    public Map<String, Object> ossGetUserDetail(Map<String, String> param) {
        return null;
    }

    @Override
    public void ossDeleteUser(Map<String, String> param) {

    }

    @Override
    public void globalUpdateByDTO(OrgAddUpdateDTO param) {

    }

    @Override
    public void addUsers(OrgAddOrDeleteUserParam param) {

    }

    @Override
    public void deleteUsers(OrgAddOrDeleteUserParam param) {

    }

    @Override
    public void addRoles(OrgAddOrDeleteRoleParam param) {

    }

    @Override
    public void deleteRoles(OrgAddOrDeleteRoleParam param) {

    }

    @Override
    public List<UserOrgInfo> admin_getUserOrgInfo(String userId) {
        return null;
    }

    @Override
    public void admin_replaceUserOrg(ReplaceUserOrgParam param) {

    }

    @Override
    public Map<String, AuthOrg> getByIds(Set<String> ids) {
        return null;
    }

    @Override
    public void updateDataPermissionCode(AuthApplication application) {

    }
}
